package com.conversationboard.view;

import java.sql.SQLException;
import java.util.List;

import com.conversationboard.model.Board;
import com.conversationboard.model.BoardAdmin;
import com.conversationboard.model.BoardAdmins;
import com.conversationboard.model.Boards;

public class BoardAdminsDisplay {

    public static String display() throws SQLException {

        List<BoardAdmin> boardAdmins = BoardAdmins.get();
        StringBuilder buffer = new StringBuilder();

        buffer.append("<table class='table'>");

        buffer.append("<tr class='row'>");
        buffer.append("<td class='header'><strong>Login ID</strong></td>");
        buffer.append("<td class='header'><strong>Board</strong></td>");
        buffer.append("<td class='header'><strong>Revoke</strong></td>");
        buffer.append("</tr>");

        int i = 0;

        for (BoardAdmin boardAdmin : boardAdmins) {

            Board board = Boards.getBoard(boardAdmin.getBoardId());

            buffer.append("<tr class='row'>");
            buffer.append("<td class='cell'>" + boardAdmin.getLoginId() + "</td>\n");
            buffer.append("<td class='cell'>" + board.getName() + "</td>\n");
            buffer.append("<input type='hidden' name='loginid" + i + "' value='" + boardAdmin.getLoginId() + "'></input>");
            buffer.append("<input type='hidden' name='boardid" + i + "' value='" + boardAdmin.getBoardId() + "'></input>");
            buffer.append("<td class='cell'><input type='radio' name='radio' value='" + i + "'></input></td>\n");
            i++;

            buffer.append("</tr>");
        }

        buffer.append("</table>");

        return buffer.toString();

    }

}
